'''
@File    :   demo.py    
@License :   (C)Copyright 2019-2020, CETC28

@Modify Time      @Author    @Version    @Desciption
------------      -------    --------    -----------
19-8-16 上午8:47   ShenCL      1.0         None
'''
from model import SiameseNetwork, Siamese
import torch
from PIL import Image
from torch.autograd import Variable
import numpy as np
from torchvision import transforms
import torch.nn.functional as F


model_path = "/home/scl/py/孪生/siamese-pytorch-master/train_model/model-inter-1001.pt"
net = Siamese()

if torch.cuda.is_available():
    net = torch.nn.DataParallel(net)
    model = net.cuda()

print('loading trained model from {0}'.format(model_path))

# 导入已经训练好的模型
model.load_state_dict(torch.load(model_path))

img1 = Image.open("/home/scl/py/OCR/TestImage/test/21/不舒服的不是9.png").resize((160, 40)).convert('L')
img2 = Image.open("/home/scl/py/OCR/TestImage/test/21/不舒服的不是1.png").resize((160, 40)).convert('L')
# img1 = Image.open("/home/scl/data/omniglot-master/omniglot-master/python/images_evaluation/Angelic/character01/0965_02.png").convert('L')
# img2 = Image.open("/home/scl/data/omniglot-master/omniglot-master/python/images_evaluation/Angelic/character01/0965_07.png").convert('L')
# img1 = Image.open("/home/scl/data/omniglot-master/omniglot-master/python/images_evaluation/Angelic/character16/0980_01.png").convert('L')
# img2 = Image.open("/home/scl/data/omniglot-master/omniglot-master/python/images_evaluation/Angelic/character16/0980_02.png").convert('L')
img1.show()
img2.show()

trans = transforms.ToTensor()

img1, img2 = trans(img1).cuda(), trans(img2).cuda()
img1 = img1.view(1, *img1.size())
img2 = img2.view(1, *img2.size())
img1 = Variable(img1)
img2 = Variable(img2)

model.eval()
with torch.no_grad():
    # output1, output2 = net.forward(test1, test2)
    output = model.forward(img1, img2)



print('output = {}'.format(output.item()))
pred = torch.gt(output, 0.9).float().cpu().item()
print('pred = {}'.format(pred))

# output1, output2 = model.forward(img1, img2)
# euclidean_distance = F.pairwise_distance(output1, output2).data.cpu().numpy()
# print(euclidean_distance)




